package com.example.bookkeep.Utils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

public class OkHttpUtil {
    private static OkHttpClient singleton;
    //非常有必要，要不此类还是可以被new，但是无法避免反射，好恶心
    private OkHttpUtil(){

    }
    //单例模式
    public static OkHttpClient getInstance() {
        if (singleton == null)
        {
            synchronized (OkHttpUtil.class)
            {
                if (singleton == null) {

                    singleton = new OkHttpClient().newBuilder()
                            .connectTimeout(100000L, TimeUnit.MILLISECONDS)
                            .readTimeout(100000L, TimeUnit.MILLISECONDS)
                            .writeTimeout(100000L, TimeUnit.MILLISECONDS)
                            .retryOnConnectionFailure(true)
                            .build();
                }
            }
        }
        return singleton;
    }
}
